//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package org.quickserver.net.qsadmin.gui;

import java.awt.BorderLayout;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.logging.Logger;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;

public class HeaderPanel extends JPanel {
    private static Logger logger = Logger.getLogger(HeaderPanel.class.getName());
    private ClassLoader classLoader = this.getClass().getClassLoader();
    public ImageIcon logo;
    public ImageIcon logoAbout;
    private JLabel logoLabel;
    private JPanel leftPanel;
    private JPanel rightPanel;
    private JLabel productName;
    private JLabel status;
    private JButton login;
    private String statusTxt1;
    private String statusTxt2;
    private String statusMsg;
    private GridBagConstraints gbc;
    private LoginDialog loginDialog;
    private final JFrame parentFrame;
    private QSAdminMain qsadminMain;

    public HeaderPanel(QSAdminMain qsadminMain, JFrame parentFrame) {
        this.logo = new ImageIcon(this.classLoader.getResource("icons/logo.gif"));
        this.logoAbout = new ImageIcon(this.classLoader.getResource("icons/logo.png"));
        this.statusTxt1 = "<html><font style=\"font-size:10pt;color:#535353\"><b> Status : ";
        this.statusTxt2 = "</b></font>";
        this.statusMsg = "Not Connected";
        this.parentFrame = parentFrame;
        this.qsadminMain = qsadminMain;
        this.gbc = new GridBagConstraints();
        this.logoLabel = new JLabel(this.logoAbout, 0);
        this.productName = new JLabel("<html><font style=\"font-size:20pt;color:#535353\"> <b>QSAdmin GUI</b></font>", 2);
        this.status = new JLabel(this.statusTxt1 + this.statusMsg + this.statusTxt2);
        this.login = new JButton("<html><font style=\"font-size:10pt;color:#535353\"><b>Login</b></font>");
        this.login.setMnemonic('L');
        this.login.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                HeaderPanel.this.handleLoginLogout();
            }
        });
        this.leftPanel = new JPanel();
        this.leftPanel.setLayout(new GridBagLayout());
        this.gbc.insets = new Insets(2, 2, 2, 2);
        this.gbc.weighty = 0.0D;
        this.gbc.weightx = 0.0D;
        this.gbc.gridx = 0;
        this.gbc.gridy = 0;
        this.gbc.gridheight = 1;
        this.gbc.gridwidth = 1;
        this.gbc.anchor = 17;
        this.gbc.fill = 0;
        this.leftPanel.add(this.productName, this.gbc);
        this.gbc.gridx = 0;
        this.gbc.gridy = 1;
        this.gbc.weightx = 0.7D;
        this.gbc.weighty = 0.7D;
        this.gbc.gridheight = 1;
        this.gbc.anchor = 13;
        this.gbc.fill = 1;
        this.leftPanel.add(this.status, this.gbc);
        this.rightPanel = new JPanel();
        this.rightPanel.setLayout(new GridBagLayout());
        this.gbc.insets = new Insets(0, 0, 0, 0);
        this.gbc.weighty = 0.0D;
        this.gbc.weightx = 0.0D;
        this.gbc.gridx = 0;
        this.gbc.gridy = 0;
        this.gbc.gridheight = 1;
        this.gbc.gridwidth = 1;
        this.gbc.anchor = 10;
        this.gbc.fill = 0;
        this.rightPanel.add(this.logoLabel, this.gbc);
        this.gbc.gridy = 1;
        this.gbc.gridx = 0;
        this.gbc.weightx = 0.8D;
        this.gbc.weighty = 0.8D;
        this.gbc.gridheight = 1;
        this.gbc.gridwidth = 1;
        this.gbc.insets = new Insets(1, 1, 1, 1);
        this.gbc.anchor = 10;
        this.gbc.fill = 1;
        this.rightPanel.add(this.login, this.gbc);
        this.setLayout(new BorderLayout(0, 10));
        this.add(this.rightPanel, "East");
        this.add(this.leftPanel, "Center");
    }

    public void setStatus(String msg) {
        this.statusMsg = msg;
        this.status.setText(this.statusTxt1 + this.statusMsg + this.statusTxt2);
    }

    public String getStatus() {
        return this.statusMsg;
    }

    public void setLoginText() {
        this.login.setText("<html><font style=\"font-size:10pt;color:#535353\"><b>Login</b></font>");
    }

    public void setLogoutText() {
        this.login.setText("<html><font style=\"font-size:10pt;color:#535353\"><b>Logout</b></font>");
    }

    public void handleLoginLogout() {
        Thread performer;
        if (!this.qsadminMain.isConnected()) {
            if (this.loginDialog == null) {
                this.loginDialog = new LoginDialog(this.parentFrame);
            }

            this.loginDialog.show();
            if (this.loginDialog.isOk()) {
                performer = new Thread(new Runnable() {
                    public void run() {
                        String[] r = HeaderPanel.this.loginDialog.getValues();

                        try {
                            boolean flag = HeaderPanel.this.qsadminMain.doLogin(r[0], Integer.parseInt(r[1]), r[2], r[3]);
                            if (flag) {
                                HeaderPanel.this.setLogoutText();
                            } else {
                                HeaderPanel.this.setLoginText();
                                HeaderPanel.this.handleLoginLogout();
                            }
                        } catch (Exception var3) {
                            HeaderPanel.logger.warning("Error logging in : " + var3);
                            HeaderPanel.this.setLoginText();
                        }

                    }
                }, "QsAdminGUI-LoginThread");
                performer.start();
            }
        } else {
            performer = new Thread(new Runnable() {
                public void run() {
                    try {
                        HeaderPanel.this.qsadminMain.doLogout();
                        HeaderPanel.this.setLoginText();
                    } catch (Exception var2) {
                        HeaderPanel.logger.warning("Error logging in : " + var2);
                    }

                }
            }, "QsAdminGUI-LogoutThread");
            performer.start();
        }

    }
}
